1
- # ###############################
2
- # Frontend dependencies builder
3
- #
4
- FROM node:12 AS frontend-base
5
-
6
- WORKDIR /app
7
- COPY ["./package.json" , "./package-lock.json" , "prepare_django_assets.js" , "/app/" ]
8
- COPY ./kitsune/sumo/static/sumo /app/kitsune/sumo/static/sumo
9
- RUN npm run production
10
-
11
- # ###############################
12
- # Python dependencies builder
13
- #
1
+ # ######################
2
+ # Common dependencies #
3
+ # ######################
14
4
FROM python:3.9-buster AS base
15
5
16
6
WORKDIR /app
@@ -26,83 +16,90 @@ RUN python -m venv /venv
26
16
RUN pip install --upgrade "pip==21.0.1"
27
17
RUN useradd -d /app -M --uid 1000 --shell /usr/sbin/nologin kitsune
28
18
19
+ RUN apt-get update && apt-get install apt-transport-https && \
20
+ curl -sL https://deb.nodesource.com/setup_12.x | bash -
29
21
RUN apt-get update && \
30
22
apt-get install -y --no-install-recommends \
31
23
gettext build-essential \
32
24
libxml2-dev libxslt1-dev zlib1g-dev git \
33
25
libjpeg-dev libffi-dev libssl-dev libxslt1.1 \
34
- libmariadb3 mariadb-client && \
26
+ libmariadb3 mariadb-client \
27
+ optipng nodejs zip && \
35
28
rm -rf /var/lib/apt/lists/*
36
29
37
30
COPY ./requirements/*.txt /app/requirements/
38
-
39
- RUN pip install --no-cache-dir --require-hashes -r requirements/default.txt && \
40
- pip install --no-cache-dir --require-hashes -r requirements/dev.txt
41
-
42
- ARG GIT_SHA=head
43
- ENV GIT_SHA=${GIT_SHA}
31
+ RUN pip install --no-cache-dir --require-hashes -r requirements/default.txt
44
32
45
33
46
- # ###############################
47
- # Developer image
48
- #
49
- FROM base AS base-dev
50
- RUN apt-get update && apt-get install apt-transport-https && \
51
- curl -sL https://deb.nodesource.com/setup_12.x | bash -
52
- RUN apt-get update && apt-get install -y --no-install-recommends optipng nodejs zip && \
53
- rm -rf /var/lib/apt/lists/*
34
+ # ####################
35
+ # Development image #
36
+ # ####################
37
+ FROM base AS dev
54
38
39
+ RUN pip install --no-cache-dir --require-hashes -r requirements/dev.txt
55
40
56
- # ###############################
57
- # Fetch locales
58
- #
59
- FROM python:3.9-buster AS locales
60
41
61
- WORKDIR /app
42
+ # ########################
43
+ # Frontend dependencies #
44
+ # ########################
45
+ FROM base AS base-frontend
62
46
63
- RUN apt-get update && \
64
- apt-get install -y --no-install-recommends gettext
47
+ COPY ./package*.json /app/
48
+ RUN npm run install-prod && npm run copy:protocol
65
49
66
- ENV PATH="/venv/bin:$PATH"
50
+ COPY prepare_django_assets.js .
51
+ RUN npm run postinstall
67
52
68
- COPY --from=base /venv /venv
53
+ COPY kitsune/sumo/static/sumo/scss kitsune/sumo/static/sumo/scss
54
+ RUN npm run build:scss && npm run build:postcss
69
55
70
56
COPY . .
57
+ RUN cp .env-build .env && \
58
+ ./manage.py nunjucks_precompile
71
59
72
- ARG LOCALE_ENV=master
73
- ENV LOCALE_ENV=${LOCALE_ENV}
74
- RUN ./docker/bin/fetch-l10n-files.sh
75
- RUN ./scripts/compile-linted-mo.sh && \
76
- find ./locale ! -name '*.mo' -type f -delete
77
60
78
- ARG GIT_SHA=head
79
- ENV GIT_SHA ${GIT_SHA}
61
+ # #######################
62
+ # Testing dependencies #
63
+ # #######################
64
+ FROM base AS test-deps
80
65
66
+ RUN pip install --no-cache-dir --require-hashes -r requirements/test.txt
81
67
82
- # ###############################
83
- # Staticfiles builder
84
- #
85
- FROM base-dev AS staticfiles
86
68
87
- COPY --from=frontend-base --chown=kitsune:kitsune /app/assets /app/assets
88
- COPY --from=frontend-base --chown=kitsune:kitsune /app/node_modules /app/node_modules
89
- COPY --from=locales /app/locale /app/locale
69
+ # ################
70
+ # Testing image #
71
+ # ################
72
+ FROM base-frontend AS test
90
73
91
- COPY . .
74
+ COPY --from=test-deps /venv /venv
92
75
93
- RUN cp .env-build .env && \
94
- ./manage.py nunjucks_precompile && \
76
+ RUN cp .env-test .env && \
95
77
./manage.py compilejsi18n && \
78
+ ./manage.py collectstatic --noinput
79
+
80
+
81
+ # #########################
82
+ # Production dependences #
83
+ # #########################
84
+ FROM base-frontend AS prod-deps
85
+
86
+ ARG LOCALE_ENV=master
87
+ ENV LOCALE_ENV=${LOCALE_ENV}
88
+ RUN ./docker/bin/fetch-l10n-files.sh
89
+ RUN ./scripts/compile-linted-mo.sh && \
90
+ find ./locale ! -name '*.mo' -type f -delete
91
+
92
+ RUN ./manage.py compilejsi18n && \
96
93
# minify jsi18n files:
97
94
find jsi18n/ -name "*.js" -exec sh -c 'npx uglifyjs "$1" -o "${1%.js}-min.js"' sh {} \; && \
98
95
./manage.py collectstatic --noinput && \
99
96
npx svgo -r -f static
100
97
101
98
102
- # ###############################
103
- # Full prod image sans locales
104
- #
105
- FROM python:3.9-slim-buster AS full-no-locales
99
+ # #########################
100
+ # Clean production image #
101
+ # #########################
102
+ FROM python:3.9-slim-buster AS prod
106
103
107
104
WORKDIR /app
108
105
@@ -113,32 +110,25 @@ ENV LANG=C.UTF-8
113
110
ENV PYTHONDONTWRITEBYTECODE=1
114
111
ENV PYTHONUNBUFFERED=1
115
112
113
+ RUN groupadd --gid 1000 kitsune && useradd -g kitsune --uid 1000 --shell /usr/sbin/nologin kitsune
114
+
115
+ COPY --from=prod-deps --chown=kitsune:kitsune /venv /venv
116
+ COPY --from=prod-deps --chown=kitsune:kitsune /app/locale /app/locale
117
+ COPY --from=prod-deps --chown=kitsune:kitsune /app/static /app/static
118
+
119
+ COPY --chown=kitsune:kitsune . .
120
+
121
+ # apt-get after copying everything to ensure we're always getting the latest packages in the prod image
116
122
RUN apt-get update && \
123
+ apt-get upgrade && \
117
124
apt-get install -y --no-install-recommends \
118
125
libmariadb3 optipng mariadb-client \
119
126
libxslt1.1 && \
120
127
rm -rf /var/lib/apt/lists/*
121
128
122
- RUN groupadd --gid 1000 kitsune && useradd -g kitsune --uid 1000 --shell /usr/sbin/nologin kitsune
123
-
124
- COPY --from=base --chown=kitsune:kitsune /venv /venv
125
- COPY --from=staticfiles --chown=kitsune:kitsune /app/static /app/static
126
-
127
- COPY --chown=kitsune:kitsune . .
128
-
129
129
RUN mkdir /app/media && chown kitsune:kitsune /app/media
130
130
131
131
USER kitsune
132
132
133
133
ARG GIT_SHA=head
134
134
ENV GIT_SHA ${GIT_SHA}
135
-
136
-
137
- # ###############################
138
- # Full final prod image
139
- #
140
- FROM full-no-locales AS full
141
-
142
- USER root
143
- COPY --from=locales --chown=kitsune:kitsune /app/locale /app/locale
144
- USER kitsune
0 commit comments